package com.cty.huffmancode;

/*
 *
 * 赫夫曼树用的结点
 * */
public class Node implements Comparable<Node> {
    Byte data;
    int weight;
    Node left;
    Node right;

    public Node(Byte data, int weight) {
        this.weight = weight;
        this.data = data;
    }

    public String toString() {
        return "[data = " + data + "weight = " + weight + "]";
    }

    //前序遍历
    public void preOrder() {
        System.out.println(this);
        if (this.left != null) {
            this.left.preOrder();
        }
        if (this.right != null) {
            this.right.preOrder();
        }
    }

    @Override
    public int compareTo(Node o) {
        return this.weight - o.weight;
    }
}
